package com.gz.servlet_my;

import com.gz.utils.WebUtils;
import com.gz.tomcat.http.GzRequest;
import com.gz.tomcat.http.GzResponse;

import javax.servlet.ServletException;
import java.io.IOException;
import java.io.OutputStream;

//!!注意
//当你发现有错误然后修改过来依然报错时
//看看你的target下的文件是否修改，如果target文件依然是之前的，那一定会发生之前的错误！！
public class GzCalServlet extends GzHttpServlet{

    @Override
    public void doGet(GzRequest request, GzResponse response) throws IOException {
        int num1= WebUtils.parseInt(request.getParameter("num1"),0);
        int num2= WebUtils.parseInt(request.getParameter("num2"),0);
        int sum= num1+num2;
        OutputStream outputStream = response.getOutputStream();
        String respHeader = response.getRespHeader();
        String resMessage=respHeader+"<h1> num1+num2="+num1+"+"+num2+"="+sum+"</h1>";
        outputStream.write(resMessage.getBytes());
        outputStream.flush();
        outputStream.close();
    }

    @Override
    public void doPost(GzRequest request, GzResponse response) throws IOException {
        doGet(request, response);
    }


}
